<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of MySQL
 *
 * @author Raul
 */
class MySQL {
    private $connection;
    private $connected = false;

    public function createConnection() {
        require_once 'config.inc.php';
        //$this->connection = mysql_connect("mysql5.das-computer-board.de", "db290069_2", "hhekwolf");
        //mysql_select_db("db290069_2");
        $this->connection = mysql_connect("localhost", "root", "root");
        mysql_select_db("schildweb");
        //$this->connection = mysql_connect("localhost", "anadmin", "aieebN!");
        //mysql_select_db("anadmin");
        //echo mysql_client_encoding();
        mysql_set_charset("utf8");
        //echo mysql_client_encoding();
        $this->connected = true;
    }

    public function executeQuery($query) {
        if($this->connected === false)
        {
            $this->createConnection();
        }
        return mysql_query($query);//mysql_real_escape_string($query));
    }

    public function getObjects($query) {
        $result = $this->executeQuery($query);
        $rows = mysql_num_rows($result);
        $resultArray;
        for ($index = 0; $index < $rows; $index++) {
            $resultArray[$index] = mysql_fetch_object($result);
        }
        return $resultArray;
    }

    public function getArray($query) {
        $result = $this->executeQuery($query);
        if($result === false) {
            echo mysql_error();
            return null;
        }
        $rows = mysql_num_rows($result);
        $resultArray;
        for ($index = 0; $index < $rows; $index++) {
            $resultArray[$index] = mysql_fetch_array($result, MYSQL_ASSOC);
        }
        return $resultArray;
    }

    public function escapeParameter($param) {
        if($this->connected === false)
        {
            $this->createConnection();
        }
        return mysql_real_escape_string($param);
    }
}
?>
